<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>onclick</title>
    <script type="text/javascript">
        window.onload=function () {
            document.getElementById("btn").onclick=function () {
                displaymessage();
            }
            };
        function displaymessage() {
            alert("你好！");
        }
    </script>
</head>
<body>
<input type="button" value="单击我" id="btn" name="btn">
</body>
</html>